use :: libc;
extern "C" {
    pub type event_base;
    pub type evbuffer;
    pub type bufferevent_ops;
    pub type args;
    pub type tmuxpeer;
    pub type hyperlinks;
    pub type screen_write_cline;
    pub type screen_sel;
    pub type screen_titles;
    pub type environ;
    pub type options;
    pub type format_tree;
    pub type input_ctx;
    pub type cmds;
    pub type tty_key;
    pub type tty_code;
    pub type format_job_tree;
    pub type control_state;
    pub type cmd;
    pub type options_array_item;
    pub type options_entry;
    pub type args_entry;
    fn toupper(_: i32) -> i32;
    fn getpwuid(__uid: __uid_t) -> *mut passwd;
    fn free(_: *mut libc::c_void);
    fn memcpy(_: *mut libc::c_void, _: *const libc::c_void, _: u64) -> *mut libc::c_void;
    fn time(__timer: *mut time_t) -> time_t;
    fn getuid() -> __uid_t;
    fn evbuffer_new() -> *mut evbuffer;
    fn evbuffer_free(buf: *mut evbuffer);
    fn evbuffer_add_vprintf(buf: *mut evbuffer, fmt: *const i8, ap: ::core::ffi::VaList) -> i32;
    fn xcalloc(_: size_t, _: size_t) -> *mut libc::c_void;
    fn xstrdup(_: *const i8) -> *mut i8;
    fn xasprintf(_: *mut *mut i8, _: *const i8, _: ...) -> i32;
    fn xvasprintf(_: *mut *mut i8, _: *const i8, _: ::core::ffi::VaList) -> i32;
    fn xsnprintf(_: *mut i8, _: size_t, _: *const i8, _: ...) -> i32;
    fn proc_get_peer_uid(_: *mut tmuxpeer) -> uid_t;
    static mut cfg_finished: i32;
    fn cfg_add_cause(_: *const i8, _: ...);
    fn format_create(_: *mut client, _: *mut cmdq_item, _: i32, _: i32) -> *mut format_tree;
    fn format_free(_: *mut format_tree);
    fn format_merge(_: *mut format_tree, _: *mut format_tree);
    fn format_add(_: *mut format_tree, _: *const i8, _: *const i8, _: ...);
    fn options_get(_: *mut options, _: *const i8) -> *mut options_entry;
    fn options_array_first(_: *mut options_entry) -> *mut options_array_item;
    fn options_array_next(_: *mut options_array_item) -> *mut options_array_item;
    fn options_array_item_value(_: *mut options_array_item) -> *mut options_value;
    fn args_print(_: *mut args) -> *mut i8;
    fn args_get(_: *mut args, _: u_char) -> *const i8;
    fn args_first(_: *mut args, _: *mut *mut args_entry) -> u_char;
    fn args_next(_: *mut *mut args_entry) -> u_char;
    fn args_count(_: *mut args) -> u_int;
    fn args_string(_: *mut args, _: u_int) -> *const i8;
    fn args_first_value(_: *mut args, _: u_char) -> *mut args_value;
    fn args_next_value(_: *mut args_value) -> *mut args_value;
    fn cmd_find_target(
        _: *mut cmd_find_state,
        _: *mut cmdq_item,
        _: *const i8,
        _: cmd_find_type,
        _: i32,
    ) -> i32;
    fn cmd_find_client(_: *mut cmdq_item, _: *const i8, _: i32) -> *mut client;
    fn cmd_find_clear_state(_: *mut cmd_find_state, _: i32);
    fn cmd_find_valid_state(_: *mut cmd_find_state) -> i32;
    fn cmd_find_copy_state(_: *mut cmd_find_state, _: *mut cmd_find_state);
    fn cmd_find_from_client(_: *mut cmd_find_state, _: *mut client, _: i32) -> i32;
    fn cmd_get_entry(_: *mut cmd) -> *const cmd_entry;
    fn cmd_get_args(_: *mut cmd) -> *mut args;
    fn cmd_get_group(_: *mut cmd) -> u_int;
    fn cmd_get_source(_: *mut cmd, _: *mut *const i8, _: *mut u_int);
    fn cmd_print(_: *mut cmd) -> *mut i8;
    fn cmd_list_free(_: *mut cmd_list);
    fn cmd_list_first(_: *mut cmd_list) -> *mut cmd;
    fn cmd_list_next(_: *mut cmd) -> *mut cmd;
    static mut global_s_options: *mut options;
    fn file_error(_: *mut client, _: *const i8, _: ...);
    fn server_add_message(_: *const i8, _: ...);
    fn server_client_unref(_: *mut client);
    fn key_string_lookup_key(_: key_code, _: i32) -> *const i8;
    fn server_client_print(_: *mut client, _: i32, _: *mut evbuffer);
    fn status_message_set(_: *mut client, _: i32, _: i32, _: i32, _: *const i8, _: ...);
    fn control_write(_: *mut client, _: *const i8, _: ...);
    fn utf8_sanitize(_: *const i8) -> *mut i8;
    fn fatalx(_: *const i8, _: ...) -> !;
    fn log_debug(_: *const i8, _: ...);
    fn log_get_level() -> i32;
}
pub type __builtin_va_list = [__va_list_tag; 1];
#[derive(Copy, Clone)]
#[repr(C)]
pub struct __va_list_tag {
    pub gp_offset: u32,
    pub fp_offset: u32,
    pub overflow_arg_area: *mut libc::c_void,
    pub reg_save_area: *mut libc::c_void,
}
pub type __u_char = u8;
pub type __u_short = u16;
pub type __u_int = u32;
pub type __uint8_t = u8;
pub type __uint64_t = u64;
pub type __uid_t = u32;
pub type __gid_t = u32;
pub type __pid_t = i32;
pub type __time_t = i64;
pub type __suseconds_t = i64;
pub type u_char = __u_char;
pub type u_short = __u_short;
pub type u_int = __u_int;
pub type uid_t = __uid_t;
pub type pid_t = __pid_t;
pub type time_t = __time_t;
pub type size_t = u64;
#[derive(Copy, Clone)]
#[repr(C)]
pub struct timeval {
    pub tv_sec: __time_t,
    pub tv_usec: __suseconds_t,
}
#[derive(Copy, Clone)]
#[repr(C)]
pub struct passwd {
    pub pw_name: *mut i8,
    pub pw_passwd: *mut i8,
    pub pw_uid: __uid_t,
    pub pw_gid: __gid_t,
    pub pw_gecos: *mut i8,
    pub pw_dir: *mut i8,
    pub pw_shell: *mut i8,
}
pub type va_list = __builtin_va_list;
pub type cc_t = u8;
pub type speed_t = u32;
pub type tcflag_t = u32;
#[derive(Copy, Clone)]
#[repr(C)]
pub struct termios {
    pub c_iflag: tcflag_t,
    pub c_oflag: tcflag_t,
    pub c_cflag: tcflag_t,
    pub c_lflag: tcflag_t,
    pub c_line: cc_t,
    pub c_cc: [cc_t; 32],
    pub c_ispeed: speed_t,
    pub c_ospeed: speed_t,
}
pub type uint8_t = __uint8_t;
pub type uint64_t = __uint64_t;
#[derive(Copy, Clone)]
#[repr(C)]
pub struct event {
    pub ev_evcallback: event_callback,
    pub ev_timeout_pos: C2RustUnnamed_4,
    pub ev_fd: i32,
    pub ev_base: *mut event_base,
    pub ev_: C2RustUnnamed,
    pub ev_events: i16,
    pub ev_res: i16,
    pub ev_timeout: timeval,
}
#[derive(Copy, Clone)]
#[repr(C)]
pub union C2RustUnnamed {
    pub ev_io: C2RustUnnamed_2,
    pub ev_signal: C2RustUnnamed_0,
}
#[derive(Copy, Clone)]
#[repr(C)]
pub struct C2RustUnnamed_0 {
    pub ev_signal_next: C2RustUnnamed_1,
    pub ev_ncalls: i16,
    pub ev_pncalls: *mut i16,
}
#[derive(Copy, Clone)]
#[repr(C)]
pub struct C2RustUnnamed_1 {
    pub le_next: *mut event,
    pub le_prev: *mut *mut event,
}
#[derive(Copy, Clone)]
#[repr(C)]
pub struct C2RustUnnamed_2 {
    pub ev_io_next: C2RustUnnamed_3,
    pub ev_timeout: timeval,
}
#[derive(Copy, Clone)]
#[repr(C)]
pub struct C2RustUnnamed_3 {
    pub le_next: *mut event,
    pub le_prev: *mut *mut event,
}
#[derive(Copy, Clone)]
#[repr(C)]
pub union C2RustUnnamed_4 {
    pub ev_next_with_common_timeout: C2RustUnnamed_5,
    pub min_heap_idx: i32,
}
#[derive(Copy, Clone)]
#[repr(C)]
pub struct C2RustUnnamed_5 {
    pub tqe_next: *mut event,
    pub tqe_prev: *mut *mut event,
}
#[derive(Copy, Clone)]
#[repr(C)]
pub struct event_callback {
    pub evcb_active_next: C2RustUnnamed_7,
    pub evcb_flags: i16,
    pub evcb_pri: uint8_t,
    pub evcb_closure: uint8_t,
    pub evcb_cb_union: C2RustUnnamed_6,
    pub evcb_arg: *mut libc::c_void,
}
#[derive(Copy, Clone)]
#[repr(C)]
pub union C2RustUnnamed_6 {
    pub evcb_callback: Option<unsafe extern "C" fn(i32, i16, *mut libc::c_void) -> ()>,
    pub evcb_selfcb: Option<unsafe extern "C" fn(*mut event_callback, *mut libc::c_void) -> ()>,
    pub evcb_evfinalize: Option<unsafe extern "C" fn(*mut event, *mut libc::c_void) -> ()>,
    pub evcb_cbfinalize: Option<unsafe extern "C" fn(*mut event_callback, *mut libc::c_void) -> ()>,
}
#[derive(Copy, Clone)]
#[repr(C)]
pub struct C2RustUnnamed_7 {
    pub tqe_next: *mut event_callback,
    pub tqe_prev: *mut *mut event_callback,
}
#[derive(Copy, Clone)]
#[repr(C)]
pub struct bufferevent {
    pub ev_base: *mut event_base,
    pub be_ops: *const bufferevent_ops,
    pub ev_read: event,
    pub ev_write: event,
    pub input: *mut evbuffer,
    pub output: *mut evbuffer,
    pub wm_read: event_watermark,
    pub wm_write: event_watermark,
    pub readcb: bufferevent_data_cb,
    pub writecb: bufferevent_data_cb,
    pub errorcb: bufferevent_event_cb,
    pub cbarg: *mut libc::c_void,
    pub timeout_read: timeval,
    pub timeout_write: timeval,
    pub enabled: i16,
}
pub type bufferevent_event_cb =
    Option<unsafe extern "C" fn(*mut bufferevent, i16, *mut libc::c_void) -> ()>;
pub type bufferevent_data_cb =
    Option<unsafe extern "C" fn(*mut bufferevent, *mut libc::c_void) -> ()>;
#[derive(Copy, Clone)]
#[repr(C)]
pub struct event_watermark {
    pub low: size_t,
    pub high: size_t,
}
pub type bitstr_t = u8;
pub type msgtype = u32;
pub const MSG_READ_CANCEL: msgtype = 307;
pub const MSG_WRITE_CLOSE: msgtype = 306;
pub const MSG_WRITE_READY: msgtype = 305;
pub const MSG_WRITE: msgtype = 304;
pub const MSG_WRITE_OPEN: msgtype = 303;
pub const MSG_READ_DONE: msgtype = 302;
pub const MSG_READ: msgtype = 301;
pub const MSG_READ_OPEN: msgtype = 300;
pub const MSG_FLAGS: msgtype = 218;
pub const MSG_EXEC: msgtype = 217;
pub const MSG_WAKEUP: msgtype = 216;
pub const MSG_UNLOCK: msgtype = 215;
pub const MSG_SUSPEND: msgtype = 214;
pub const MSG_OLDSTDOUT: msgtype = 213;
pub const MSG_OLDSTDIN: msgtype = 212;
pub const MSG_OLDSTDERR: msgtype = 211;
pub const MSG_SHUTDOWN: msgtype = 210;
pub const MSG_SHELL: msgtype = 209;
pub const MSG_RESIZE: msgtype = 208;
pub const MSG_READY: msgtype = 207;
pub const MSG_LOCK: msgtype = 206;
pub const MSG_EXITING: msgtype = 205;
pub const MSG_EXITED: msgtype = 204;
pub const MSG_EXIT: msgtype = 203;
pub const MSG_DETACHKILL: msgtype = 202;
pub const MSG_DETACH: msgtype = 201;
pub const MSG_COMMAND: msgtype = 200;
pub const MSG_IDENTIFY_TERMINFO: msgtype = 112;
pub const MSG_IDENTIFY_LONGFLAGS: msgtype = 111;
pub const MSG_IDENTIFY_STDOUT: msgtype = 110;
pub const MSG_IDENTIFY_FEATURES: msgtype = 109;
pub const MSG_IDENTIFY_CWD: msgtype = 108;
pub const MSG_IDENTIFY_CLIENTPID: msgtype = 107;
pub const MSG_IDENTIFY_DONE: msgtype = 106;
pub const MSG_IDENTIFY_ENVIRON: msgtype = 105;
pub const MSG_IDENTIFY_STDIN: msgtype = 104;
pub const MSG_IDENTIFY_OLDCWD: msgtype = 103;
pub const MSG_IDENTIFY_TTYNAME: msgtype = 102;
pub const MSG_IDENTIFY_TERM: msgtype = 101;
pub const MSG_IDENTIFY_FLAGS: msgtype = 100;
pub const MSG_VERSION: msgtype = 12;
#[derive(Copy, Clone)]
#[repr(C)]
pub struct client {
    pub name: *const i8,
    pub peer: *mut tmuxpeer,
    pub queue: *mut cmdq_list,
    pub windows: client_windows,
    pub control_state: *mut control_state,
    pub pause_age: u_int,
    pub pid: pid_t,
    pub fd: i32,
    pub out_fd: i32,
    pub event: event,
    pub retval: i32,
    pub creation_time: timeval,
    pub activity_time: timeval,
    pub last_activity_time: timeval,
    pub environ: *mut environ,
    pub jobs: *mut format_job_tree,
    pub title: *mut i8,
    pub path: *mut i8,
    pub cwd: *const i8,
    pub term_name: *mut i8,
    pub term_features: i32,
    pub term_type: *mut i8,
    pub term_caps: *mut *mut i8,
    pub term_ncaps: u_int,
    pub ttyname: *mut i8,
    pub tty: tty,
    pub written: size_t,
    pub discarded: size_t,
    pub redraw: size_t,
    pub repeat_timer: event,
    pub click_timer: event,
    pub click_button: u_int,
    pub click_event: mouse_event,
    pub status: status_line,
    pub flags: uint64_t,
    pub exit_type: C2RustUnnamed_30,
    pub exit_msgtype: msgtype,
    pub exit_session: *mut i8,
    pub exit_message: *mut i8,
    pub keytable: *mut key_table,
    pub last_key: key_code,
    pub redraw_panes: uint64_t,
    pub redraw_scrollbars: uint64_t,
    pub message_ignore_keys: i32,
    pub message_ignore_styles: i32,
    pub message_string: *mut i8,
    pub message_timer: event,
    pub prompt_string: *mut i8,
    pub prompt_buffer: *mut utf8_data,
    pub prompt_last: *mut i8,
    pub prompt_index: size_t,
    pub prompt_inputcb: prompt_input_cb,
    pub prompt_freecb: prompt_free_cb,
    pub prompt_data: *mut libc::c_void,
    pub prompt_hindex: [u_int; 4],
    pub prompt_mode: C2RustUnnamed_27,
    pub prompt_saved: *mut utf8_data,
    pub prompt_flags: i32,
    pub prompt_type: prompt_type,
    pub prompt_cursor: i32,
    pub session: *mut session,
    pub last_session: *mut session,
    pub references: i32,
    pub pan_window: *mut libc::c_void,
    pub pan_ox: u_int,
    pub pan_oy: u_int,
    pub overlay_check: overlay_check_cb,
    pub overlay_mode: overlay_mode_cb,
    pub overlay_draw: overlay_draw_cb,
    pub overlay_key: overlay_key_cb,
    pub overlay_free: overlay_free_cb,
    pub overlay_resize: overlay_resize_cb,
    pub overlay_data: *mut libc::c_void,
    pub overlay_timer: event,
    pub files: client_files,
    pub clipboard_panes: *mut u_int,
    pub clipboard_npanes: u_int,
    pub entry: C2RustUnnamed_8,
}
#[derive(Copy, Clone)]
#[repr(C)]
pub struct C2RustUnnamed_8 {
    pub tqe_next: *mut client,
    pub tqe_prev: *mut *mut client,
}
#[derive(Copy, Clone)]
#[repr(C)]
pub struct client_files {
    pub rbh_root: *mut client_file,
}
#[derive(Copy, Clone)]
#[repr(C)]
pub struct client_file {
    pub c: *mut client,
    pub peer: *mut tmuxpeer,
    pub tree: *mut client_files,
    pub references: i32,
    pub stream: i32,
    pub path: *mut i8,
    pub buffer: *mut evbuffer,
    pub event: *mut bufferevent,
    pub fd: i32,
    pub error: i32,
    pub closed: i32,
    pub cb: client_file_cb,
    pub data: *mut libc::c_void,
    pub entry: C2RustUnnamed_9,
}
#[derive(Copy, Clone)]
#[repr(C)]
pub struct C2RustUnnamed_9 {
    pub rbe_left: *mut client_file,
    pub rbe_right: *mut client_file,
    pub rbe_parent: *mut client_file,
    pub rbe_color: i32,
}
pub type client_file_cb = Option<
    unsafe extern "C" fn(*mut client, *const i8, i32, i32, *mut evbuffer, *mut libc::c_void) -> (),
>;
pub type overlay_resize_cb = Option<unsafe extern "C" fn(*mut client, *mut libc::c_void) -> ()>;
pub type overlay_free_cb = Option<unsafe extern "C" fn(*mut client, *mut libc::c_void) -> ()>;
pub type overlay_key_cb =
    Option<unsafe extern "C" fn(*mut client, *mut libc::c_void, *mut key_event) -> i32>;
#[derive(Copy, Clone)]
#[repr(C)]
pub struct key_event {
    pub key: key_code,
    pub m: mouse_event,
    pub buf: *mut i8,
    pub len: size_t,
}
#[derive(Copy, Clone)]
#[repr(C)]
pub struct mouse_event {
    pub valid: i32,
    pub ignore: i32,
    pub key: key_code,
    pub statusat: i32,
    pub statuslines: u_int,
    pub x: u_int,
    pub y: u_int,
    pub b: u_int,
    pub lx: u_int,
    pub ly: u_int,
    pub lb: u_int,
    pub ox: u_int,
    pub oy: u_int,
    pub s: i32,
    pub w: i32,
    pub wp: i32,
    pub sgr_type: u_int,
    pub sgr_b: u_int,
}
pub type key_code = u64;
pub type overlay_draw_cb =
    Option<unsafe extern "C" fn(*mut client, *mut libc::c_void, *mut screen_redraw_ctx) -> ()>;
#[derive(Copy, Clone)]
#[repr(C)]
pub struct screen_redraw_ctx {
    pub c: *mut client,
    pub statuslines: u_int,
    pub statustop: i32,
    pub pane_status: i32,
    pub pane_lines: pane_lines,
    pub pane_scrollbars: i32,
    pub pane_scrollbars_pos: i32,
    pub no_pane_gc: grid_cell,
    pub no_pane_gc_set: i32,
    pub sx: u_int,
    pub sy: u_int,
    pub ox: u_int,
    pub oy: u_int,
}
#[derive(Copy, Clone)]
#[repr(C)]
pub struct grid_cell {
    pub data: utf8_data,
    pub attr: u_short,
    pub flags: u_char,
    pub fg: i32,
    pub bg: i32,
    pub us: i32,
    pub link: u_int,
}
#[derive(Copy, Clone)]
#[repr(C)]
pub struct utf8_data {
    pub data: [u_char; 21],
    pub have: u_char,
    pub size: u_char,
    pub width: u_char,
}
pub type pane_lines = u32;
pub const PANE_LINES_NUMBER: pane_lines = 4;
pub const PANE_LINES_SIMPLE: pane_lines = 3;
pub const PANE_LINES_HEAVY: pane_lines = 2;
pub const PANE_LINES_DOUBLE: pane_lines = 1;
pub const PANE_LINES_SINGLE: pane_lines = 0;
pub type overlay_mode_cb = Option<
    unsafe extern "C" fn(*mut client, *mut libc::c_void, *mut u_int, *mut u_int) -> *mut screen,
>;
#[derive(Copy, Clone)]
#[repr(C)]
pub struct screen {
    pub title: *mut i8,
    pub path: *mut i8,
    pub titles: *mut screen_titles,
    pub grid: *mut grid,
    pub cx: u_int,
    pub cy: u_int,
    pub cstyle: screen_cursor_style,
    pub default_cstyle: screen_cursor_style,
    pub ccolour: i32,
    pub default_ccolour: i32,
    pub rupper: u_int,
    pub rlower: u_int,
    pub mode: i32,
    pub default_mode: i32,
    pub saved_cx: u_int,
    pub saved_cy: u_int,
    pub saved_grid: *mut grid,
    pub saved_cell: grid_cell,
    pub saved_flags: i32,
    pub tabs: *mut bitstr_t,
    pub sel: *mut screen_sel,
    pub write_list: *mut screen_write_cline,
    pub hyperlinks: *mut hyperlinks,
}
#[derive(Copy, Clone)]
#[repr(C)]
pub struct grid {
    pub flags: i32,
    pub sx: u_int,
    pub sy: u_int,
    pub hscrolled: u_int,
    pub hsize: u_int,
    pub hlimit: u_int,
    pub linedata: *mut grid_line,
}
#[derive(Copy, Clone)]
#[repr(C)]
pub struct grid_line {
    pub celldata: *mut grid_cell_entry,
    pub cellused: u_int,
    pub cellsize: u_int,
    pub extddata: *mut grid_extd_entry,
    pub extdsize: u_int,
    pub flags: i32,
    pub time: time_t,
}
#[derive(Copy, Clone)]
#[repr(C, packed)]
pub struct grid_extd_entry {
    pub data: utf8_char,
    pub attr: u_short,
    pub flags: u_char,
    pub fg: i32,
    pub bg: i32,
    pub us: i32,
    pub link: u_int,
}
pub type utf8_char = u_int;
#[derive(Copy, Clone)]
#[repr(C, packed)]
pub struct grid_cell_entry {
    pub c2rust_unnamed: C2RustUnnamed_10,
    pub flags: u_char,
}
#[derive(Copy, Clone)]
#[repr(C)]
pub union C2RustUnnamed_10 {
    pub offset: u_int,
    pub data: C2RustUnnamed_11,
}
#[derive(Copy, Clone)]
#[repr(C)]
pub struct C2RustUnnamed_11 {
    pub attr: u_char,
    pub fg: u_char,
    pub bg: u_char,
    pub data: u_char,
}
pub type screen_cursor_style = u32;
pub const SCREEN_CURSOR_BAR: screen_cursor_style = 3;
pub const SCREEN_CURSOR_UNDERLINE: screen_cursor_style = 2;
pub const SCREEN_CURSOR_BLOCK: screen_cursor_style = 1;
pub const SCREEN_CURSOR_DEFAULT: screen_cursor_style = 0;
pub type overlay_check_cb = Option<
    unsafe extern "C" fn(
        *mut client,
        *mut libc::c_void,
        u_int,
        u_int,
        u_int,
        *mut overlay_ranges,
    ) -> (),
>;
#[derive(Copy, Clone)]
#[repr(C)]
pub struct overlay_ranges {
    pub px: [u_int; 3],
    pub nx: [u_int; 3],
}
#[derive(Copy, Clone)]
#[repr(C)]
pub struct session {
    pub id: u_int,
    pub name: *mut i8,
    pub cwd: *const i8,
    pub creation_time: timeval,
    pub last_attached_time: timeval,
    pub activity_time: timeval,
    pub last_activity_time: timeval,
    pub lock_timer: event,
    pub curw: *mut winlink,
    pub lastw: winlink_stack,
    pub windows: winlinks,
    pub statusat: i32,
    pub statuslines: u_int,
    pub options: *mut options,
    pub flags: i32,
    pub attached: u_int,
    pub tio: *mut termios,
    pub environ: *mut environ,
    pub references: i32,
    pub gentry: C2RustUnnamed_13,
    pub entry: C2RustUnnamed_12,
}
#[derive(Copy, Clone)]
#[repr(C)]
pub struct C2RustUnnamed_12 {
    pub rbe_left: *mut session,
    pub rbe_right: *mut session,
    pub rbe_parent: *mut session,
    pub rbe_color: i32,
}
#[derive(Copy, Clone)]
#[repr(C)]
pub struct C2RustUnnamed_13 {
    pub tqe_next: *mut session,
    pub tqe_prev: *mut *mut session,
}
#[derive(Copy, Clone)]
#[repr(C)]
pub struct winlinks {
    pub rbh_root: *mut winlink,
}
#[derive(Copy, Clone)]
#[repr(C)]
pub struct winlink {
    pub idx: i32,
    pub session: *mut session,
    pub window: *mut window,
    pub flags: i32,
    pub entry: C2RustUnnamed_16,
    pub wentry: C2RustUnnamed_15,
    pub sentry: C2RustUnnamed_14,
}
#[derive(Copy, Clone)]
#[repr(C)]
pub struct C2RustUnnamed_14 {
    pub tqe_next: *mut winlink,
    pub tqe_prev: *mut *mut winlink,
}
#[derive(Copy, Clone)]
#[repr(C)]
pub struct C2RustUnnamed_15 {
    pub tqe_next: *mut winlink,
    pub tqe_prev: *mut *mut winlink,
}
#[derive(Copy, Clone)]
#[repr(C)]
pub struct C2RustUnnamed_16 {
    pub rbe_left: *mut winlink,
    pub rbe_right: *mut winlink,
    pub rbe_parent: *mut winlink,
    pub rbe_color: i32,
}
#[derive(Copy, Clone)]
#[repr(C)]
pub struct window {
    pub id: u_int,
    pub latest: *mut libc::c_void,
    pub name: *mut i8,
    pub name_event: event,
    pub name_time: timeval,
    pub alerts_timer: event,
    pub offset_timer: event,
    pub activity_time: timeval,
    pub active: *mut window_pane,
    pub last_panes: window_panes,
    pub panes: window_panes,
    pub lastlayout: i32,
    pub layout_root: *mut layout_cell,
    pub saved_layout_root: *mut layout_cell,
    pub old_layout: *mut i8,
    pub sx: u_int,
    pub sy: u_int,
    pub manual_sx: u_int,
    pub manual_sy: u_int,
    pub xpixel: u_int,
    pub ypixel: u_int,
    pub new_sx: u_int,
    pub new_sy: u_int,
    pub new_xpixel: u_int,
    pub new_ypixel: u_int,
    pub fill_character: *mut utf8_data,
    pub flags: i32,
    pub alerts_queued: i32,
    pub alerts_entry: C2RustUnnamed_19,
    pub options: *mut options,
    pub references: u_int,
    pub winlinks: C2RustUnnamed_18,
    pub entry: C2RustUnnamed_17,
}
#[derive(Copy, Clone)]
#[repr(C)]
pub struct C2RustUnnamed_17 {
    pub rbe_left: *mut window,
    pub rbe_right: *mut window,
    pub rbe_parent: *mut window,
    pub rbe_color: i32,
}
#[derive(Copy, Clone)]
#[repr(C)]
pub struct C2RustUnnamed_18 {
    pub tqh_first: *mut winlink,
    pub tqh_last: *mut *mut winlink,
}
#[derive(Copy, Clone)]
#[repr(C)]
pub struct C2RustUnnamed_19 {
    pub tqe_next: *mut window,
    pub tqe_prev: *mut *mut window,
}
#[derive(Copy, Clone)]
#[repr(C)]
pub struct layout_cell {
    pub type_0: layout_type,
    pub parent: *mut layout_cell,
    pub sx: u_int,
    pub sy: u_int,
    pub xoff: u_int,
    pub yoff: u_int,
    pub wp: *mut window_pane,
    pub cells: layout_cells,
    pub entry: C2RustUnnamed_20,
}
#[derive(Copy, Clone)]
#[repr(C)]
pub struct C2RustUnnamed_20 {
    pub tqe_next: *mut layout_cell,
    pub tqe_prev: *mut *mut layout_cell,
}
#[derive(Copy, Clone)]
#[repr(C)]
pub struct layout_cells {
    pub tqh_first: *mut layout_cell,
    pub tqh_last: *mut *mut layout_cell,
}
#[derive(Copy, Clone)]
#[repr(C)]
pub struct window_pane {
    pub id: u_int,
    pub active_point: u_int,
    pub window: *mut window,
    pub options: *mut options,
    pub layout_cell: *mut layout_cell,
    pub saved_layout_cell: *mut layout_cell,
    pub sx: u_int,
    pub sy: u_int,
    pub xoff: u_int,
    pub yoff: u_int,
    pub flags: i32,
    pub sb_slider_y: u_int,
    pub sb_slider_h: u_int,
    pub argc: i32,
    pub argv: *mut *mut i8,
    pub shell: *mut i8,
    pub cwd: *mut i8,
    pub pid: pid_t,
    pub tty: [i8; 32],
    pub status: i32,
    pub dead_time: timeval,
    pub fd: i32,
    pub event: *mut bufferevent,
    pub offset: window_pane_offset,
    pub base_offset: size_t,
    pub resize_queue: window_pane_resizes,
    pub resize_timer: event,
    pub ictx: *mut input_ctx,
    pub cached_gc: grid_cell,
    pub cached_active_gc: grid_cell,
    pub palette: colour_palette,
    pub pipe_fd: i32,
    pub pipe_event: *mut bufferevent,
    pub pipe_offset: window_pane_offset,
    pub screen: *mut screen,
    pub base: screen,
    pub status_screen: screen,
    pub status_size: size_t,
    pub modes: C2RustUnnamed_24,
    pub searchstr: *mut i8,
    pub searchregex: i32,
    pub border_gc_set: i32,
    pub border_gc: grid_cell,
    pub control_bg: i32,
    pub control_fg: i32,
    pub scrollbar_style: style,
    pub entry: C2RustUnnamed_23,
    pub sentry: C2RustUnnamed_22,
    pub tree_entry: C2RustUnnamed_21,
}
#[derive(Copy, Clone)]
#[repr(C)]
pub struct C2RustUnnamed_21 {
    pub rbe_left: *mut window_pane,
    pub rbe_right: *mut window_pane,
    pub rbe_parent: *mut window_pane,
    pub rbe_color: i32,
}
#[derive(Copy, Clone)]
#[repr(C)]
pub struct C2RustUnnamed_22 {
    pub tqe_next: *mut window_pane,
    pub tqe_prev: *mut *mut window_pane,
}
#[derive(Copy, Clone)]
#[repr(C)]
pub struct C2RustUnnamed_23 {
    pub tqe_next: *mut window_pane,
    pub tqe_prev: *mut *mut window_pane,
}
#[derive(Copy, Clone)]
#[repr(C)]
pub struct style {
    pub gc: grid_cell,
    pub ignore: i32,
    pub fill: i32,
    pub align: style_align,
    pub list: style_list,
    pub range_type: style_range_type,
    pub range_argument: u_int,
    pub range_string: [i8; 16],
    pub width: i32,
    pub pad: i32,
    pub default_type: style_default_type,
}
pub type style_default_type = u32;
pub const STYLE_DEFAULT_POP: style_default_type = 2;
pub const STYLE_DEFAULT_PUSH: style_default_type = 1;
pub const STYLE_DEFAULT_BASE: style_default_type = 0;
pub type style_range_type = u32;
pub const STYLE_RANGE_USER: style_range_type = 6;
pub const STYLE_RANGE_SESSION: style_range_type = 5;
pub const STYLE_RANGE_WINDOW: style_range_type = 4;
pub const STYLE_RANGE_PANE: style_range_type = 3;
pub const STYLE_RANGE_RIGHT: style_range_type = 2;
pub const STYLE_RANGE_LEFT: style_range_type = 1;
pub const STYLE_RANGE_NONE: style_range_type = 0;
pub type style_list = u32;
pub const STYLE_LIST_RIGHT_MARKER: style_list = 4;
pub const STYLE_LIST_LEFT_MARKER: style_list = 3;
pub const STYLE_LIST_FOCUS: style_list = 2;
pub const STYLE_LIST_ON: style_list = 1;
pub const STYLE_LIST_OFF: style_list = 0;
pub type style_align = u32;
pub const STYLE_ALIGN_ABSOLUTE_CENTRE: style_align = 4;
pub const STYLE_ALIGN_RIGHT: style_align = 3;
pub const STYLE_ALIGN_CENTRE: style_align = 2;
pub const STYLE_ALIGN_LEFT: style_align = 1;
pub const STYLE_ALIGN_DEFAULT: style_align = 0;
#[derive(Copy, Clone)]
#[repr(C)]
pub struct C2RustUnnamed_24 {
    pub tqh_first: *mut window_mode_entry,
    pub tqh_last: *mut *mut window_mode_entry,
}
#[derive(Copy, Clone)]
#[repr(C)]
pub struct window_mode_entry {
    pub wp: *mut window_pane,
    pub swp: *mut window_pane,
    pub mode: *const window_mode,
    pub data: *mut libc::c_void,
    pub screen: *mut screen,
    pub prefix: u_int,
    pub entry: C2RustUnnamed_25,
}
#[derive(Copy, Clone)]
#[repr(C)]
pub struct C2RustUnnamed_25 {
    pub tqe_next: *mut window_mode_entry,
    pub tqe_prev: *mut *mut window_mode_entry,
}
#[derive(Copy, Clone)]
#[repr(C)]
pub struct window_mode {
    pub name: *const i8,
    pub default_format: *const i8,
    pub init: Option<
        unsafe extern "C" fn(*mut window_mode_entry, *mut cmd_find_state, *mut args) -> *mut screen,
    >,
    pub free: Option<unsafe extern "C" fn(*mut window_mode_entry) -> ()>,
    pub resize: Option<unsafe extern "C" fn(*mut window_mode_entry, u_int, u_int) -> ()>,
    pub update: Option<unsafe extern "C" fn(*mut window_mode_entry) -> ()>,
    pub key: Option<
        unsafe extern "C" fn(
            *mut window_mode_entry,
            *mut client,
            *mut session,
            *mut winlink,
            key_code,
            *mut mouse_event,
        ) -> (),
    >,
    pub key_table: Option<unsafe extern "C" fn(*mut window_mode_entry) -> *const i8>,
    pub command: Option<
        unsafe extern "C" fn(
            *mut window_mode_entry,
            *mut client,
            *mut session,
            *mut winlink,
            *mut args,
            *mut mouse_event,
        ) -> (),
    >,
    pub formats: Option<unsafe extern "C" fn(*mut window_mode_entry, *mut format_tree) -> ()>,
}
#[derive(Copy, Clone)]
#[repr(C)]
pub struct cmd_find_state {
    pub flags: i32,
    pub current: *mut cmd_find_state,
    pub s: *mut session,
    pub wl: *mut winlink,
    pub w: *mut window,
    pub wp: *mut window_pane,
    pub idx: i32,
}
#[derive(Copy, Clone)]
#[repr(C)]
pub struct window_pane_offset {
    pub used: size_t,
}
#[derive(Copy, Clone)]
#[repr(C)]
pub struct colour_palette {
    pub fg: i32,
    pub bg: i32,
    pub palette: *mut i32,
    pub default_palette: *mut i32,
}
#[derive(Copy, Clone)]
#[repr(C)]
pub struct window_pane_resizes {
    pub tqh_first: *mut window_pane_resize,
    pub tqh_last: *mut *mut window_pane_resize,
}
#[derive(Copy, Clone)]
#[repr(C)]
pub struct window_pane_resize {
    pub sx: u_int,
    pub sy: u_int,
    pub osx: u_int,
    pub osy: u_int,
    pub entry: C2RustUnnamed_26,
}
#[derive(Copy, Clone)]
#[repr(C)]
pub struct C2RustUnnamed_26 {
    pub tqe_next: *mut window_pane_resize,
    pub tqe_prev: *mut *mut window_pane_resize,
}
pub type layout_type = u32;
pub const LAYOUT_WINDOWPANE: layout_type = 2;
pub const LAYOUT_TOPBOTTOM: layout_type = 1;
pub const LAYOUT_LEFTRIGHT: layout_type = 0;
#[derive(Copy, Clone)]
#[repr(C)]
pub struct window_panes {
    pub tqh_first: *mut window_pane,
    pub tqh_last: *mut *mut window_pane,
}
#[derive(Copy, Clone)]
#[repr(C)]
pub struct winlink_stack {
    pub tqh_first: *mut winlink,
    pub tqh_last: *mut *mut winlink,
}
pub type prompt_type = u32;
pub const PROMPT_TYPE_INVALID: prompt_type = 255;
pub const PROMPT_TYPE_WINDOW_TARGET: prompt_type = 3;
pub const PROMPT_TYPE_TARGET: prompt_type = 2;
pub const PROMPT_TYPE_SEARCH: prompt_type = 1;
pub const PROMPT_TYPE_COMMAND: prompt_type = 0;
pub type C2RustUnnamed_27 = u32;
pub const PROMPT_COMMAND: C2RustUnnamed_27 = 1;
pub const PROMPT_ENTRY: C2RustUnnamed_27 = 0;
pub type prompt_free_cb = Option<unsafe extern "C" fn(*mut libc::c_void) -> ()>;
pub type prompt_input_cb =
    Option<unsafe extern "C" fn(*mut client, *mut libc::c_void, *const i8, i32) -> i32>;
#[derive(Copy, Clone)]
#[repr(C)]
pub struct key_table {
    pub name: *const i8,
    pub activity_time: timeval,
    pub key_bindings: key_bindings,
    pub default_key_bindings: key_bindings,
    pub references: u_int,
    pub entry: C2RustUnnamed_28,
}
#[derive(Copy, Clone)]
#[repr(C)]
pub struct C2RustUnnamed_28 {
    pub rbe_left: *mut key_table,
    pub rbe_right: *mut key_table,
    pub rbe_parent: *mut key_table,
    pub rbe_color: i32,
}
#[derive(Copy, Clone)]
#[repr(C)]
pub struct key_bindings {
    pub rbh_root: *mut key_binding,
}
#[derive(Copy, Clone)]
#[repr(C)]
pub struct key_binding {
    pub key: key_code,
    pub cmdlist: *mut cmd_list,
    pub note: *const i8,
    pub flags: i32,
    pub entry: C2RustUnnamed_29,
}
#[derive(Copy, Clone)]
#[repr(C)]
pub struct C2RustUnnamed_29 {
    pub rbe_left: *mut key_binding,
    pub rbe_right: *mut key_binding,
    pub rbe_parent: *mut key_binding,
    pub rbe_color: i32,
}
#[derive(Copy, Clone)]
#[repr(C)]
pub struct cmd_list {
    pub references: i32,
    pub group: u_int,
    pub list: *mut cmds,
}
pub type C2RustUnnamed_30 = u32;
pub const CLIENT_EXIT_DETACH: C2RustUnnamed_30 = 2;
pub const CLIENT_EXIT_SHUTDOWN: C2RustUnnamed_30 = 1;
pub const CLIENT_EXIT_RETURN: C2RustUnnamed_30 = 0;
#[derive(Copy, Clone)]
#[repr(C)]
pub struct status_line {
    pub timer: event,
    pub screen: screen,
    pub active: *mut screen,
    pub references: i32,
    pub style: grid_cell,
    pub entries: [status_line_entry; 5],
}
#[derive(Copy, Clone)]
#[repr(C)]
pub struct status_line_entry {
    pub expanded: *mut i8,
    pub ranges: style_ranges,
}
#[derive(Copy, Clone)]
#[repr(C)]
pub struct style_ranges {
    pub tqh_first: *mut style_range,
    pub tqh_last: *mut *mut style_range,
}
#[derive(Copy, Clone)]
#[repr(C)]
pub struct style_range {
    pub type_0: style_range_type,
    pub argument: u_int,
    pub string: [i8; 16],
    pub start: u_int,
    pub end: u_int,
    pub entry: C2RustUnnamed_31,
}
#[derive(Copy, Clone)]
#[repr(C)]
pub struct C2RustUnnamed_31 {
    pub tqe_next: *mut style_range,
    pub tqe_prev: *mut *mut style_range,
}
#[derive(Copy, Clone)]
#[repr(C)]
pub struct tty {
    pub client: *mut client,
    pub start_timer: event,
    pub clipboard_timer: event,
    pub last_requests: time_t,
    pub sx: u_int,
    pub sy: u_int,
    pub xpixel: u_int,
    pub ypixel: u_int,
    pub cx: u_int,
    pub cy: u_int,
    pub cstyle: screen_cursor_style,
    pub ccolour: i32,
    pub oflag: i32,
    pub oox: u_int,
    pub ooy: u_int,
    pub osx: u_int,
    pub osy: u_int,
    pub mode: i32,
    pub fg: i32,
    pub bg: i32,
    pub rlower: u_int,
    pub rupper: u_int,
    pub rleft: u_int,
    pub rright: u_int,
    pub event_in: event,
    pub in_0: *mut evbuffer,
    pub event_out: event,
    pub out: *mut evbuffer,
    pub timer: event,
    pub discarded: size_t,
    pub tio: termios,
    pub cell: grid_cell,
    pub last_cell: grid_cell,
    pub flags: i32,
    pub term: *mut tty_term,
    pub mouse_last_x: u_int,
    pub mouse_last_y: u_int,
    pub mouse_last_b: u_int,
    pub mouse_drag_flag: i32,
    pub mouse_scrolling_flag: i32,
    pub mouse_slider_mpos: i32,
    pub mouse_drag_update: Option<unsafe extern "C" fn(*mut client, *mut mouse_event) -> ()>,
    pub mouse_drag_release: Option<unsafe extern "C" fn(*mut client, *mut mouse_event) -> ()>,
    pub key_timer: event,
    pub key_tree: *mut tty_key,
}
#[derive(Copy, Clone)]
#[repr(C)]
pub struct tty_term {
    pub name: *mut i8,
    pub tty: *mut tty,
    pub features: i32,
    pub acs: [[i8; 2]; 256],
    pub codes: *mut tty_code,
    pub flags: i32,
    pub entry: C2RustUnnamed_32,
}
#[derive(Copy, Clone)]
#[repr(C)]
pub struct C2RustUnnamed_32 {
    pub le_next: *mut tty_term,
    pub le_prev: *mut *mut tty_term,
}
#[derive(Copy, Clone)]
#[repr(C)]
pub struct client_windows {
    pub rbh_root: *mut client_window,
}
#[derive(Copy, Clone)]
#[repr(C)]
pub struct client_window {
    pub window: u_int,
    pub pane: *mut window_pane,
    pub sx: u_int,
    pub sy: u_int,
    pub entry: C2RustUnnamed_33,
}
#[derive(Copy, Clone)]
#[repr(C)]
pub struct C2RustUnnamed_33 {
    pub rbe_left: *mut client_window,
    pub rbe_right: *mut client_window,
    pub rbe_parent: *mut client_window,
    pub rbe_color: i32,
}
#[derive(Copy, Clone)]
#[repr(C)]
pub struct cmdq_list {
    pub item: *mut cmdq_item,
    pub list: cmdq_item_list,
}
#[derive(Copy, Clone)]
#[repr(C)]
pub struct cmdq_item_list {
    pub tqh_first: *mut cmdq_item,
    pub tqh_last: *mut *mut cmdq_item,
}
#[derive(Copy, Clone)]
#[repr(C)]
pub struct cmdq_item {
    pub name: *mut i8,
    pub queue: *mut cmdq_list,
    pub next: *mut cmdq_item,
    pub client: *mut client,
    pub target_client: *mut client,
    pub type_0: cmdq_type,
    pub group: u_int,
    pub number: u_int,
    pub time: time_t,
    pub flags: i32,
    pub state: *mut cmdq_state,
    pub source: cmd_find_state,
    pub target: cmd_find_state,
    pub cmdlist: *mut cmd_list,
    pub cmd: *mut cmd,
    pub cb: cmdq_cb,
    pub data: *mut libc::c_void,
    pub entry: C2RustUnnamed_34,
}
#[derive(Copy, Clone)]
#[repr(C)]
pub struct C2RustUnnamed_34 {
    pub tqe_next: *mut cmdq_item,
    pub tqe_prev: *mut *mut cmdq_item,
}
pub type cmdq_cb = Option<unsafe extern "C" fn(*mut cmdq_item, *mut libc::c_void) -> cmd_retval>;
pub type cmd_retval = i32;
pub const CMD_RETURN_STOP: cmd_retval = 2;
pub const CMD_RETURN_WAIT: cmd_retval = 1;
pub const CMD_RETURN_NORMAL: cmd_retval = 0;
pub const CMD_RETURN_ERROR: cmd_retval = -1;
#[derive(Copy, Clone)]
#[repr(C)]
pub struct cmdq_state {
    pub references: i32,
    pub flags: i32,
    pub formats: *mut format_tree,
    pub event: key_event,
    pub current: cmd_find_state,
}
pub type cmdq_type = u32;
pub const CMDQ_CALLBACK: cmdq_type = 1;
pub const CMDQ_COMMAND: cmdq_type = 0;
pub type args_type = u32;
pub const ARGS_COMMANDS: args_type = 2;
pub const ARGS_STRING: args_type = 1;
pub const ARGS_NONE: args_type = 0;
#[derive(Copy, Clone)]
#[repr(C)]
pub struct args_value {
    pub type_0: args_type,
    pub c2rust_unnamed: C2RustUnnamed_36,
    pub cached: *mut i8,
    pub entry: C2RustUnnamed_35,
}
#[derive(Copy, Clone)]
#[repr(C)]
pub struct C2RustUnnamed_35 {
    pub tqe_next: *mut args_value,
    pub tqe_prev: *mut *mut args_value,
}
#[derive(Copy, Clone)]
#[repr(C)]
pub union C2RustUnnamed_36 {
    pub string: *mut i8,
    pub cmdlist: *mut cmd_list,
}
pub type args_parse_type = u32;
pub const ARGS_PARSE_COMMANDS: args_parse_type = 3;
pub const ARGS_PARSE_COMMANDS_OR_STRING: args_parse_type = 2;
pub const ARGS_PARSE_STRING: args_parse_type = 1;
pub const ARGS_PARSE_INVALID: args_parse_type = 0;
pub type args_parse_cb =
    Option<unsafe extern "C" fn(*mut args, u_int, *mut *mut i8) -> args_parse_type>;
#[derive(Copy, Clone)]
#[repr(C)]
pub struct args_parse {
    pub template: *const i8,
    pub lower: i32,
    pub upper: i32,
    pub cb: args_parse_cb,
}
pub type cmd_find_type = u32;
pub const CMD_FIND_SESSION: cmd_find_type = 2;
pub const CMD_FIND_WINDOW: cmd_find_type = 1;
pub const CMD_FIND_PANE: cmd_find_type = 0;
#[derive(Copy, Clone)]
#[repr(C)]
pub struct cmd_entry_flag {
    pub flag: i8,
    pub type_0: cmd_find_type,
    pub flags: i32,
}
#[derive(Copy, Clone)]
#[repr(C)]
pub struct cmd_entry {
    pub name: *const i8,
    pub alias: *const i8,
    pub args: args_parse,
    pub usage: *const i8,
    pub source: cmd_entry_flag,
    pub target: cmd_entry_flag,
    pub flags: i32,
    pub exec: Option<unsafe extern "C" fn(*mut cmd, *mut cmdq_item) -> cmd_retval>,
}
#[derive(Copy, Clone)]
#[repr(C)]
pub struct options_array {
    pub rbh_root: *mut options_array_item,
}
#[derive(Copy, Clone)]
#[repr(C)]
pub union options_value {
    pub string: *mut i8,
    pub number: i64,
    pub style: style,
    pub array: options_array,
    pub cmdlist: *mut cmd_list,
}
extern "C" fn cmdq_name(mut c: *mut client) -> *const i8 {
    static mut s: [i8; 256] = [0; 256];
    if c.is_null() {
        return b"<global>\0" as *const u8 as *const i8;
    }
    if !(unsafe { (*c).name }).is_null() {
        (unsafe {
            xsnprintf(
                s.as_mut_ptr(),
                ::core::mem::size_of::<[i8; 256]>() as u64,
                b"<%s>\0" as *const u8 as *const i8,
                (*c).name,
            )
        });
    } else {
        (unsafe {
            xsnprintf(
                s.as_mut_ptr(),
                ::core::mem::size_of::<[i8; 256]>() as u64,
                b"<%p>\0" as *const u8 as *const i8,
                c,
            )
        });
    }
    return unsafe { s.as_mut_ptr() };
}
extern "C" fn cmdq_get(mut c: *mut client) -> *mut cmdq_list {
    static mut global_queue: *mut cmdq_list = 0 as *const cmdq_list as *mut cmdq_list;
    if c.is_null() {
        if (unsafe { global_queue }).is_null() {
            (unsafe { global_queue = cmdq_new() });
        }
        return unsafe { global_queue };
    }
    return unsafe { (*c).queue };
}
#[no_mangle]
pub extern "C" fn cmdq_new() -> *mut cmdq_list {
    let mut queue: *mut cmdq_list = std::ptr::null_mut::<cmdq_list>();
    queue = (unsafe {
        xcalloc(
            1 as i32 as size_t,
            ::core::mem::size_of::<cmdq_list>() as u64,
        )
    }) as *mut cmdq_list;
    (unsafe { (*queue).list.tqh_first = std::ptr::null_mut::<cmdq_item>() });
    (unsafe { (*queue).list.tqh_last = &mut (*queue).list.tqh_first });
    return queue;
}
#[no_mangle]
pub extern "C" fn cmdq_free(mut queue: *mut cmdq_list) {
    if !(unsafe { (*queue).list.tqh_first }).is_null() {
        (unsafe { fatalx(b"queue not empty\0" as *const u8 as *const i8) });
    }
    (unsafe { free(queue as *mut libc::c_void) });
}
#[no_mangle]
pub extern "C" fn cmdq_get_name(mut item: *mut cmdq_item) -> *const i8 {
    return unsafe { (*item).name };
}
#[no_mangle]
pub extern "C" fn cmdq_get_client(mut item: *mut cmdq_item) -> *mut client {
    return unsafe { (*item).client };
}
#[no_mangle]
pub extern "C" fn cmdq_get_target_client(mut item: *mut cmdq_item) -> *mut client {
    return unsafe { (*item).target_client };
}
#[no_mangle]
pub extern "C" fn cmdq_get_state(mut item: *mut cmdq_item) -> *mut cmdq_state {
    return unsafe { (*item).state };
}
#[no_mangle]
pub extern "C" fn cmdq_get_target(mut item: *mut cmdq_item) -> *mut cmd_find_state {
    return unsafe { &mut (*item).target };
}
#[no_mangle]
pub extern "C" fn cmdq_get_source(mut item: *mut cmdq_item) -> *mut cmd_find_state {
    return unsafe { &mut (*item).source };
}
#[no_mangle]
pub extern "C" fn cmdq_get_event(mut item: *mut cmdq_item) -> *mut key_event {
    return unsafe { &mut (*(*item).state).event };
}
#[no_mangle]
pub extern "C" fn cmdq_get_current(mut item: *mut cmdq_item) -> *mut cmd_find_state {
    return unsafe { &mut (*(*item).state).current };
}
#[no_mangle]
pub extern "C" fn cmdq_get_flags(mut item: *mut cmdq_item) -> i32 {
    return unsafe { (*(*item).state).flags };
}
#[no_mangle]
pub extern "C" fn cmdq_new_state(
    mut current: *mut cmd_find_state,
    mut event: *mut key_event,
    mut flags: i32,
) -> *mut cmdq_state {
    let mut state: *mut cmdq_state = std::ptr::null_mut::<cmdq_state>();
    state = (unsafe {
        xcalloc(
            1 as i32 as size_t,
            ::core::mem::size_of::<cmdq_state>() as u64,
        )
    }) as *mut cmdq_state;
    (unsafe { (*state).references = 1 as i32 });
    (unsafe { (*state).flags = flags });
    if !event.is_null() {
        (unsafe {
            memcpy(
                &mut (*state).event as *mut key_event as *mut libc::c_void,
                event as *const libc::c_void,
                ::core::mem::size_of::<key_event>() as u64,
            )
        });
    } else {
        (unsafe { (*state).event.key = 0xff000000000 as u64 });
    }
    if !current.is_null() && (unsafe { cmd_find_valid_state(current) }) != 0 {
        (unsafe { cmd_find_copy_state(&mut (*state).current, current) });
    } else {
        (unsafe { cmd_find_clear_state(&mut (*state).current, 0 as i32) });
    }
    return state;
}
#[no_mangle]
pub extern "C" fn cmdq_link_state(mut state: *mut cmdq_state) -> *mut cmdq_state {
    (unsafe { (*state).references += 1 });
    return state;
}
#[no_mangle]
pub extern "C" fn cmdq_copy_state(
    mut state: *mut cmdq_state,
    mut current: *mut cmd_find_state,
) -> *mut cmdq_state {
    if !current.is_null() {
        return cmdq_new_state(current, unsafe { &mut (*state).event }, unsafe {
            (*state).flags
        });
    }
    return cmdq_new_state(
        unsafe { &mut (*state).current },
        unsafe { &mut (*state).event },
        unsafe { (*state).flags },
    );
}
#[no_mangle]
pub extern "C" fn cmdq_free_state(mut state: *mut cmdq_state) {
    (unsafe { (*state).references -= 1 });
    if (unsafe { (*state).references }) != 0 as i32 {
        return;
    }
    if !(unsafe { (*state).formats }).is_null() {
        (unsafe { format_free((*state).formats) });
    }
    (unsafe { free(state as *mut libc::c_void) });
}
#[no_mangle]
pub unsafe extern "C" fn cmdq_add_format(
    mut state: *mut cmdq_state,
    mut key: *const i8,
    mut fmt: *const i8,
    mut args: ...
) {
    let mut ap: ::core::ffi::VaListImpl;
    let mut value: *mut i8 = std::ptr::null_mut::<i8>();
    ap = args.clone();
    xvasprintf(&mut value, fmt, ap.as_va_list());
    if ((*state).formats).is_null() {
        (*state).formats = format_create(
            std::ptr::null_mut::<client>(),
            std::ptr::null_mut::<cmdq_item>(),
            0 as i32,
            0 as i32,
        );
    }
    format_add(
        (*state).formats,
        key,
        b"%s\0" as *const u8 as *const i8,
        value,
    );
    free(value as *mut libc::c_void);
}
#[no_mangle]
pub extern "C" fn cmdq_add_formats(mut state: *mut cmdq_state, mut ft: *mut format_tree) {
    if (unsafe { (*state).formats }).is_null() {
        (unsafe {
            (*state).formats = format_create(
                std::ptr::null_mut::<client>(),
                std::ptr::null_mut::<cmdq_item>(),
                0 as i32,
                0 as i32,
            )
        });
    }
    (unsafe { format_merge((*state).formats, ft) });
}
#[no_mangle]
pub extern "C" fn cmdq_merge_formats(mut item: *mut cmdq_item, mut ft: *mut format_tree) {
    let mut entry: *const cmd_entry = std::ptr::null::<cmd_entry>();
    if !(unsafe { (*item).cmd }).is_null() {
        entry = unsafe { cmd_get_entry((*item).cmd) };
        (unsafe {
            format_add(
                ft,
                b"command\0" as *const u8 as *const i8,
                b"%s\0" as *const u8 as *const i8,
                (*entry).name,
            )
        });
    }
    if !(unsafe { (*(*item).state).formats }).is_null() {
        (unsafe { format_merge(ft, (*(*item).state).formats) });
    }
}
#[no_mangle]
pub extern "C" fn cmdq_append(mut c: *mut client, mut item: *mut cmdq_item) -> *mut cmdq_item {
    let mut queue: *mut cmdq_list = cmdq_get(c);
    let mut next: *mut cmdq_item = std::ptr::null_mut::<cmdq_item>();
    loop {
        next = unsafe { (*item).next };
        (unsafe { (*item).next = std::ptr::null_mut::<cmdq_item>() });
        if !c.is_null() {
            (unsafe { (*c).references += 1 });
        }
        (unsafe { (*item).client = c });
        (unsafe { (*item).queue = queue });
        (unsafe { (*item).entry.tqe_next = std::ptr::null_mut::<cmdq_item>() });
        (unsafe { (*item).entry.tqe_prev = (*queue).list.tqh_last });
        (unsafe { *(*queue).list.tqh_last = item });
        (unsafe { (*queue).list.tqh_last = &mut (*item).entry.tqe_next });
        (unsafe {
            log_debug(
                b"%s %s: %s\0" as *const u8 as *const i8,
                (*::core::mem::transmute::<&[u8; 12], &[i8; 12]>(b"cmdq_append\0")).as_ptr(),
                cmdq_name(c),
                (*item).name,
            )
        });
        item = next;
        if item.is_null() {
            break;
        }
    }
    return unsafe { *(*((*queue).list.tqh_last as *mut cmdq_item_list)).tqh_last };
}
#[no_mangle]
pub extern "C" fn cmdq_insert_after(
    mut after: *mut cmdq_item,
    mut item: *mut cmdq_item,
) -> *mut cmdq_item {
    let mut c: *mut client = unsafe { (*after).client };
    let mut queue: *mut cmdq_list = unsafe { (*after).queue };
    let mut next: *mut cmdq_item = std::ptr::null_mut::<cmdq_item>();
    loop {
        next = unsafe { (*item).next };
        (unsafe { (*item).next = (*after).next });
        (unsafe { (*after).next = item });
        if !c.is_null() {
            (unsafe { (*c).references += 1 });
        }
        (unsafe { (*item).client = c });
        (unsafe { (*item).queue = queue });
        (unsafe { (*item).entry.tqe_next = (*after).entry.tqe_next });
        if !(unsafe { (*item).entry.tqe_next }).is_null() {
            (unsafe { (*(*item).entry.tqe_next).entry.tqe_prev = &mut (*item).entry.tqe_next });
        } else {
            (unsafe { (*queue).list.tqh_last = &mut (*item).entry.tqe_next });
        }
        (unsafe { (*after).entry.tqe_next = item });
        (unsafe { (*item).entry.tqe_prev = &mut (*after).entry.tqe_next });
        (unsafe {
            log_debug(
                b"%s %s: %s after %s\0" as *const u8 as *const i8,
                (*::core::mem::transmute::<&[u8; 18], &[i8; 18]>(b"cmdq_insert_after\0")).as_ptr(),
                cmdq_name(c),
                (*item).name,
                (*after).name,
            )
        });
        after = item;
        item = next;
        if item.is_null() {
            break;
        }
    }
    return after;
}
#[no_mangle]
pub unsafe extern "C" fn cmdq_insert_hook(
    mut s: *mut session,
    mut item: *mut cmdq_item,
    mut current: *mut cmd_find_state,
    mut fmt: *const i8,
    mut args: ...
) {
    let mut state: *mut cmdq_state = (*item).state;
    let mut cmd: *mut cmd = (*item).cmd;
    let mut args_0: *mut args = cmd_get_args(cmd);
    let mut ae: *mut args_entry = std::ptr::null_mut::<args_entry>();
    let mut av: *mut args_value = std::ptr::null_mut::<args_value>();
    let mut oo: *mut options = std::ptr::null_mut::<options>();
    let mut ap: ::core::ffi::VaListImpl;
    let mut name: *mut i8 = std::ptr::null_mut::<i8>();
    let mut tmp: [i8; 32] = [0; 32];
    let mut flag: i8 = 0;
    let mut arguments: *mut i8 = std::ptr::null_mut::<i8>();
    let mut i: u_int = 0;
    let mut value: *const i8 = std::ptr::null::<i8>();
    let mut new_item: *mut cmdq_item = std::ptr::null_mut::<cmdq_item>();
    let mut new_state: *mut cmdq_state = std::ptr::null_mut::<cmdq_state>();
    let mut o: *mut options_entry = std::ptr::null_mut::<options_entry>();
    let mut a: *mut options_array_item = std::ptr::null_mut::<options_array_item>();
    let mut cmdlist: *mut cmd_list = std::ptr::null_mut::<cmd_list>();
    if (*(*item).state).flags & 0x4 as i32 != 0 {
        return;
    }
    if s.is_null() {
        oo = global_s_options;
    } else {
        oo = (*s).options;
    }
    ap = args.clone();
    xvasprintf(&mut name, fmt, ap.as_va_list());
    o = options_get(oo, name);
    if o.is_null() {
        free(name as *mut libc::c_void);
        return;
    }
    log_debug(
        b"running hook %s (parent %p)\0" as *const u8 as *const i8,
        name,
        item,
    );
    new_state = cmdq_new_state(current, &mut (*state).event, 0x4 as i32);
    cmdq_add_format(
        new_state,
        b"hook\0" as *const u8 as *const i8,
        b"%s\0" as *const u8 as *const i8,
        name,
    );
    arguments = args_print(args_0);
    cmdq_add_format(
        new_state,
        b"hook_arguments\0" as *const u8 as *const i8,
        b"%s\0" as *const u8 as *const i8,
        arguments,
    );
    free(arguments as *mut libc::c_void);
    i = 0 as i32 as u_int;
    while i < args_count(args_0) {
        xsnprintf(
            tmp.as_mut_ptr(),
            ::core::mem::size_of::<[i8; 32]>() as u64,
            b"hook_argument_%d\0" as *const u8 as *const i8,
            i,
        );
        cmdq_add_format(
            new_state,
            tmp.as_mut_ptr(),
            b"%s\0" as *const u8 as *const i8,
            args_string(args_0, i),
        );
        i = i.wrapping_add(1);
    }
    flag = args_first(args_0, &mut ae) as i8;
    while flag as i32 != 0 as i32 {
        value = args_get(args_0, flag as u_char);
        if value.is_null() {
            xsnprintf(
                tmp.as_mut_ptr(),
                ::core::mem::size_of::<[i8; 32]>() as u64,
                b"hook_flag_%c\0" as *const u8 as *const i8,
                flag as i32,
            );
            cmdq_add_format(
                new_state,
                tmp.as_mut_ptr(),
                b"1\0" as *const u8 as *const i8,
            );
        } else {
            xsnprintf(
                tmp.as_mut_ptr(),
                ::core::mem::size_of::<[i8; 32]>() as u64,
                b"hook_flag_%c\0" as *const u8 as *const i8,
                flag as i32,
            );
            cmdq_add_format(
                new_state,
                tmp.as_mut_ptr(),
                b"%s\0" as *const u8 as *const i8,
                value,
            );
        }
        i = 0 as i32 as u_int;
        av = args_first_value(args_0, flag as u_char);
        while !av.is_null() {
            xsnprintf(
                tmp.as_mut_ptr(),
                ::core::mem::size_of::<[i8; 32]>() as u64,
                b"hook_flag_%c_%d\0" as *const u8 as *const i8,
                flag as i32,
                i,
            );
            cmdq_add_format(
                new_state,
                tmp.as_mut_ptr(),
                b"%s\0" as *const u8 as *const i8,
                (*av).c2rust_unnamed.string,
            );
            i = i.wrapping_add(1);
            av = args_next_value(av);
        }
        flag = args_next(&mut ae) as i8;
    }
    a = options_array_first(o);
    while !a.is_null() {
        cmdlist = (*options_array_item_value(a)).cmdlist;
        if !cmdlist.is_null() {
            new_item = cmdq_get_command(cmdlist, new_state);
            if !item.is_null() {
                item = cmdq_insert_after(item, new_item);
            } else {
                item = cmdq_append(std::ptr::null_mut::<client>(), new_item);
            }
        }
        a = options_array_next(a);
    }
    cmdq_free_state(new_state);
    free(name as *mut libc::c_void);
}
#[no_mangle]
pub extern "C" fn cmdq_continue(mut item: *mut cmdq_item) {
    (unsafe { (*item).flags &= !(0x2 as i32) });
}
extern "C" fn cmdq_remove(mut item: *mut cmdq_item) {
    if !(unsafe { (*item).client }).is_null() {
        (unsafe { server_client_unref((*item).client) });
    }
    if !(unsafe { (*item).cmdlist }).is_null() {
        (unsafe { cmd_list_free((*item).cmdlist) });
    }
    cmdq_free_state(unsafe { (*item).state });
    if !(unsafe { (*item).entry.tqe_next }).is_null() {
        (unsafe { (*(*item).entry.tqe_next).entry.tqe_prev = (*item).entry.tqe_prev });
    } else {
        (unsafe { (*(*item).queue).list.tqh_last = (*item).entry.tqe_prev });
    }
    (unsafe { *(*item).entry.tqe_prev = (*item).entry.tqe_next });
    (unsafe { free((*item).name as *mut libc::c_void) });
    (unsafe { free(item as *mut libc::c_void) });
}
extern "C" fn cmdq_remove_group(mut item: *mut cmdq_item) {
    let mut this: *mut cmdq_item = std::ptr::null_mut::<cmdq_item>();
    let mut next: *mut cmdq_item = std::ptr::null_mut::<cmdq_item>();
    if (unsafe { (*item).group }) == 0 as i32 as u32 {
        return;
    }
    this = unsafe { (*item).entry.tqe_next };
    while !this.is_null() {
        next = unsafe { (*this).entry.tqe_next };
        if (unsafe { (*this).group }) == (unsafe { (*item).group }) {
            cmdq_remove(this);
        }
        this = next;
    }
}
extern "C" fn cmdq_empty_command(
    mut _item: *mut cmdq_item,
    mut _data: *mut libc::c_void,
) -> cmd_retval {
    return CMD_RETURN_NORMAL;
}
#[no_mangle]
pub extern "C" fn cmdq_get_command(
    mut cmdlist: *mut cmd_list,
    mut state: *mut cmdq_state,
) -> *mut cmdq_item {
    let mut item: *mut cmdq_item = std::ptr::null_mut::<cmdq_item>();
    let mut first: *mut cmdq_item = std::ptr::null_mut::<cmdq_item>();
    let mut last: *mut cmdq_item = std::ptr::null_mut::<cmdq_item>();
    let mut cmd: *mut cmd = std::ptr::null_mut::<cmd>();
    let mut entry: *const cmd_entry = std::ptr::null::<cmd_entry>();
    let mut created: i32 = 0 as i32;
    cmd = unsafe { cmd_list_first(cmdlist) };
    if cmd.is_null() {
        return cmdq_get_callback1(
            b"cmdq_empty_command\0" as *const u8 as *const i8,
            Some(
                cmdq_empty_command
                    as unsafe extern "C" fn(*mut cmdq_item, *mut libc::c_void) -> cmd_retval,
            ),
            std::ptr::null_mut::<libc::c_void>(),
        );
    }
    if state.is_null() {
        state = cmdq_new_state(
            std::ptr::null_mut::<cmd_find_state>(),
            std::ptr::null_mut::<key_event>(),
            0 as i32,
        );
        created = 1 as i32;
    }
    while !cmd.is_null() {
        entry = unsafe { cmd_get_entry(cmd) };
        item = (unsafe {
            xcalloc(
                1 as i32 as size_t,
                ::core::mem::size_of::<cmdq_item>() as u64,
            )
        }) as *mut cmdq_item;
        (unsafe {
            xasprintf(
                &mut (*item).name as *mut *mut i8,
                b"[%s/%p]\0" as *const u8 as *const i8,
                (*entry).name,
                item,
            )
        });
        (unsafe { (*item).type_0 = CMDQ_COMMAND });
        (unsafe { (*item).group = cmd_get_group(cmd) });
        (unsafe { (*item).state = cmdq_link_state(state) });
        (unsafe { (*item).cmdlist = cmdlist });
        (unsafe { (*item).cmd = cmd });
        (unsafe { (*cmdlist).references += 1 });
        (unsafe {
            log_debug(
                b"%s: %s group %u\0" as *const u8 as *const i8,
                (*::core::mem::transmute::<&[u8; 17], &[i8; 17]>(b"cmdq_get_command\0")).as_ptr(),
                (*item).name,
                (*item).group,
            )
        });
        if first.is_null() {
            first = item;
        }
        if !last.is_null() {
            (unsafe { (*last).next = item });
        }
        last = item;
        cmd = unsafe { cmd_list_next(cmd) };
    }
    if created != 0 {
        cmdq_free_state(state);
    }
    return first;
}
extern "C" fn cmdq_find_flag(
    mut item: *mut cmdq_item,
    mut fs: *mut cmd_find_state,
    mut flag: *const cmd_entry_flag,
) -> cmd_retval {
    let mut value: *const i8 = std::ptr::null::<i8>();
    if (unsafe { (*flag).flag }) as i32 == 0 as i32 {
        (unsafe { cmd_find_from_client(fs, (*item).target_client, 0 as i32) });
        return CMD_RETURN_NORMAL;
    }
    value = unsafe { args_get(cmd_get_args((*item).cmd), (*flag).flag as u_char) };
    if (unsafe { cmd_find_target(fs, item, value, (*flag).type_0, (*flag).flags) }) != 0 as i32 {
        (unsafe { cmd_find_clear_state(fs, 0 as i32) });
        return CMD_RETURN_ERROR;
    }
    return CMD_RETURN_NORMAL;
}
extern "C" fn cmdq_add_message(mut item: *mut cmdq_item) {
    let mut c: *mut client = unsafe { (*item).client };
    let mut state: *mut cmdq_state = unsafe { (*item).state };
    let mut key: *const i8 = std::ptr::null::<i8>();
    let mut tmp: *mut i8 = std::ptr::null_mut::<i8>();
    let mut uid: uid_t = 0;
    let mut pw: *mut passwd = std::ptr::null_mut::<passwd>();
    let mut user: *mut i8 = std::ptr::null_mut::<i8>();
    tmp = unsafe { cmd_print((*item).cmd) };
    if !c.is_null() {
        uid = unsafe { proc_get_peer_uid((*c).peer) };
        if uid != -(1 as i32) as uid_t && uid != (unsafe { getuid() }) {
            pw = unsafe { getpwuid(uid) };
            if !pw.is_null() {
                (unsafe {
                    xasprintf(
                        &mut user as *mut *mut i8,
                        b"[%s]\0" as *const u8 as *const i8,
                        (*pw).pw_name,
                    )
                });
            } else {
                user = unsafe { xstrdup(b"[unknown]\0" as *const u8 as *const i8) };
            }
        } else {
            user = unsafe { xstrdup(b"\0" as *const u8 as *const i8) };
        }
        if !(unsafe { (*c).session }).is_null()
            && (unsafe { (*state).event.key }) != 0xff000000000 as u64
        {
            key = unsafe { key_string_lookup_key((*state).event.key, 0 as i32) };
            (unsafe {
                server_add_message(
                    b"%s%s key %s: %s\0" as *const u8 as *const i8,
                    (*c).name,
                    user,
                    key,
                    tmp,
                )
            });
        } else {
            (unsafe {
                server_add_message(
                    b"%s%s command: %s\0" as *const u8 as *const i8,
                    (*c).name,
                    user,
                    tmp,
                )
            });
        }
        (unsafe { free(user as *mut libc::c_void) });
    } else {
        (unsafe { server_add_message(b"command: %s\0" as *const u8 as *const i8, tmp) });
    }
    (unsafe { free(tmp as *mut libc::c_void) });
}
extern "C" fn cmdq_fire_command(mut item: *mut cmdq_item) -> cmd_retval {
    let mut current_block: u64;
    let mut name: *const i8 = cmdq_name(unsafe { (*item).client });
    let mut state: *mut cmdq_state = unsafe { (*item).state };
    let mut cmd: *mut cmd = unsafe { (*item).cmd };
    let mut args: *mut args = unsafe { cmd_get_args(cmd) };
    let mut entry: *const cmd_entry = unsafe { cmd_get_entry(cmd) };
    let mut tc: *mut client = std::ptr::null_mut::<client>();
    let mut saved: *mut client = unsafe { (*item).client };
    let mut retval: cmd_retval = CMD_RETURN_NORMAL;
    let mut fsp: *mut cmd_find_state = std::ptr::null_mut::<cmd_find_state>();
    let mut fs: cmd_find_state = cmd_find_state {
        flags: 0,
        current: std::ptr::null_mut::<cmd_find_state>(),
        s: std::ptr::null_mut::<session>(),
        wl: std::ptr::null_mut::<winlink>(),
        w: std::ptr::null_mut::<window>(),
        wp: std::ptr::null_mut::<window_pane>(),
        idx: 0,
    };
    let mut flags: i32 = 0;
    let mut quiet: i32 = 0 as i32;
    let mut tmp: *mut i8 = std::ptr::null_mut::<i8>();
    if (unsafe { cfg_finished }) != 0 {
        cmdq_add_message(item);
    }
    if (unsafe { log_get_level() }) > 1 as i32 {
        tmp = unsafe { cmd_print(cmd) };
        (unsafe {
            log_debug(
                b"%s %s: (%u) %s\0" as *const u8 as *const i8,
                (*::core::mem::transmute::<&[u8; 18], &[i8; 18]>(b"cmdq_fire_command\0")).as_ptr(),
                name,
                (*item).group,
                tmp,
            )
        });
        (unsafe { free(tmp as *mut libc::c_void) });
    }
    flags = ((unsafe { (*state).flags }) & 0x2 as i32 != 0) as i32;
    cmdq_guard(item, b"begin\0" as *const u8 as *const i8, flags);
    if (unsafe { (*item).client }).is_null() {
        (unsafe { (*item).client = cmd_find_client(item, std::ptr::null::<i8>(), 1 as i32) });
    }
    if (unsafe { (*entry).flags }) & 0x20 as i32 != 0 {
        quiet = 1 as i32;
    }
    if (unsafe { (*entry).flags }) & 0x8 as i32 != 0 {
        tc = unsafe { cmd_find_client(item, args_get(args, 'c' as i32 as u_char), quiet) };
        if tc.is_null() && quiet == 0 {
            retval = CMD_RETURN_ERROR;
            current_block = 10673917357490104332;
        } else {
            current_block = 18317007320854588510;
        }
    } else if (unsafe { (*entry).flags }) & 0x10 as i32 != 0 {
        tc = unsafe { cmd_find_client(item, args_get(args, 't' as i32 as u_char), quiet) };
        if tc.is_null() && quiet == 0 {
            retval = CMD_RETURN_ERROR;
            current_block = 10673917357490104332;
        } else {
            current_block = 18317007320854588510;
        }
    } else {
        tc = unsafe { cmd_find_client(item, std::ptr::null::<i8>(), 1 as i32) };
        current_block = 18317007320854588510;
    }
    match current_block {
        18317007320854588510 => {
            (unsafe { (*item).target_client = tc });
            retval = cmdq_find_flag(item, unsafe { &mut (*item).source }, unsafe {
                &(*entry).source
            });
            if retval as i32 != CMD_RETURN_ERROR as i32 {
                retval = cmdq_find_flag(item, unsafe { &mut (*item).target }, unsafe {
                    &(*entry).target
                });
                if retval as i32 != CMD_RETURN_ERROR as i32 {
                    retval =
                        unsafe { ((*entry).exec).expect("non-null function pointer")(cmd, item) };
                    if retval as i32 != CMD_RETURN_ERROR as i32 {
                        if (unsafe { (*entry).flags }) & 0x4 as i32 != 0 {
                            if (unsafe { cmd_find_valid_state(&mut (*item).target) }) != 0 {
                                fsp = unsafe { &mut (*item).target };
                                current_block = 8704759739624374314;
                            } else if (unsafe {
                                cmd_find_valid_state(&mut (*(*item).state).current)
                            }) != 0
                            {
                                fsp = unsafe { &mut (*(*item).state).current };
                                current_block = 8704759739624374314;
                            } else if (unsafe {
                                cmd_find_from_client(&mut fs, (*item).client, 0 as i32)
                            }) == 0 as i32
                            {
                                fsp = &mut fs;
                                current_block = 8704759739624374314;
                            } else {
                                current_block = 10673917357490104332;
                            }
                            match current_block {
                                10673917357490104332 => {}
                                _ => {
                                    (unsafe {
                                        cmdq_insert_hook(
                                            (*fsp).s,
                                            item,
                                            fsp,
                                            b"after-%s\0" as *const u8 as *const i8,
                                            (*entry).name,
                                        )
                                    });
                                }
                            }
                        }
                    }
                }
            }
        }
        _ => {}
    }
    (unsafe { (*item).client = saved });
    if retval as i32 == CMD_RETURN_ERROR as i32 {
        fsp = std::ptr::null_mut::<cmd_find_state>();
        if (unsafe { cmd_find_valid_state(&mut (*item).target) }) != 0 {
            fsp = unsafe { &mut (*item).target };
        } else if (unsafe { cmd_find_valid_state(&mut (*(*item).state).current) }) != 0 {
            fsp = unsafe { &mut (*(*item).state).current };
        } else if (unsafe { cmd_find_from_client(&mut fs, (*item).client, 0 as i32) }) == 0 as i32 {
            fsp = &mut fs;
        }
        (unsafe {
            cmdq_insert_hook(
                if !fsp.is_null() {
                    (*fsp).s
                } else {
                    std::ptr::null_mut::<session>()
                },
                item,
                fsp,
                b"command-error\0" as *const u8 as *const i8,
            )
        });
        cmdq_guard(item, b"error\0" as *const u8 as *const i8, flags);
    } else {
        cmdq_guard(item, b"end\0" as *const u8 as *const i8, flags);
    }
    return retval;
}
#[no_mangle]
pub extern "C" fn cmdq_get_callback1(
    mut name: *const i8,
    mut cb: cmdq_cb,
    mut data: *mut libc::c_void,
) -> *mut cmdq_item {
    let mut item: *mut cmdq_item = std::ptr::null_mut::<cmdq_item>();
    item = (unsafe {
        xcalloc(
            1 as i32 as size_t,
            ::core::mem::size_of::<cmdq_item>() as u64,
        )
    }) as *mut cmdq_item;
    (unsafe {
        xasprintf(
            &mut (*item).name as *mut *mut i8,
            b"[%s/%p]\0" as *const u8 as *const i8,
            name,
            item,
        )
    });
    (unsafe { (*item).type_0 = CMDQ_CALLBACK });
    (unsafe { (*item).group = 0 as i32 as u_int });
    (unsafe {
        (*item).state = cmdq_new_state(
            std::ptr::null_mut::<cmd_find_state>(),
            std::ptr::null_mut::<key_event>(),
            0 as i32,
        )
    });
    (unsafe { (*item).cb = cb });
    (unsafe { (*item).data = data });
    return item;
}
extern "C" fn cmdq_error_callback(
    mut item: *mut cmdq_item,
    mut data: *mut libc::c_void,
) -> cmd_retval {
    let mut error: *mut i8 = data as *mut i8;
    (unsafe { cmdq_error(item, b"%s\0" as *const u8 as *const i8, error) });
    (unsafe { free(error as *mut libc::c_void) });
    return CMD_RETURN_NORMAL;
}
#[no_mangle]
pub extern "C" fn cmdq_get_error(mut error: *const i8) -> *mut cmdq_item {
    return cmdq_get_callback1(
        b"cmdq_error_callback\0" as *const u8 as *const i8,
        Some(
            cmdq_error_callback
                as unsafe extern "C" fn(*mut cmdq_item, *mut libc::c_void) -> cmd_retval,
        ),
        (unsafe { xstrdup(error) }) as *mut libc::c_void,
    );
}
extern "C" fn cmdq_fire_callback(mut item: *mut cmdq_item) -> cmd_retval {
    return unsafe { ((*item).cb).expect("non-null function pointer")(item, (*item).data) };
}
#[no_mangle]
pub extern "C" fn cmdq_next(mut c: *mut client) -> u_int {
    let mut current_block: u64;
    let mut queue: *mut cmdq_list = cmdq_get(c);
    let mut name: *const i8 = cmdq_name(c);
    let mut item: *mut cmdq_item = std::ptr::null_mut::<cmdq_item>();
    let mut retval: cmd_retval = CMD_RETURN_NORMAL;
    let mut items: u_int = 0 as i32 as u_int;
    static mut number: u_int = 0;
    if (unsafe { (*queue).list.tqh_first }).is_null() {
        (unsafe {
            log_debug(
                b"%s %s: empty\0" as *const u8 as *const i8,
                (*::core::mem::transmute::<&[u8; 10], &[i8; 10]>(b"cmdq_next\0")).as_ptr(),
                name,
            )
        });
        return 0 as i32 as u_int;
    }
    if (unsafe { (*(*queue).list.tqh_first).flags }) & 0x2 as i32 != 0 {
        (unsafe {
            log_debug(
                b"%s %s: waiting\0" as *const u8 as *const i8,
                (*::core::mem::transmute::<&[u8; 10], &[i8; 10]>(b"cmdq_next\0")).as_ptr(),
                name,
            )
        });
        return 0 as i32 as u_int;
    }
    (unsafe {
        log_debug(
            b"%s %s: enter\0" as *const u8 as *const i8,
            (*::core::mem::transmute::<&[u8; 10], &[i8; 10]>(b"cmdq_next\0")).as_ptr(),
            name,
        )
    });
    loop {
        (unsafe { (*queue).item = (*queue).list.tqh_first });
        item = unsafe { (*queue).item };
        if item.is_null() {
            current_block = 7056779235015430508;
            break;
        }
        (unsafe {
            log_debug(
                b"%s %s: %s (%d), flags %x\0" as *const u8 as *const i8,
                (*::core::mem::transmute::<&[u8; 10], &[i8; 10]>(b"cmdq_next\0")).as_ptr(),
                name,
                (*item).name,
                (*item).type_0 as u32,
                (*item).flags,
            )
        });
        if (unsafe { (*item).flags }) & 0x2 as i32 != 0 {
            current_block = 781873232861654146;
            break;
        }
        if !(unsafe { (*item).flags }) & 0x1 as i32 != 0 {
            (unsafe { (*item).time = time(std::ptr::null_mut::<time_t>()) });
            (unsafe { number = number.wrapping_add(1) });
            (unsafe { (*item).number = number });
            match (unsafe { (*item).type_0 }) as u32 {
                0 => {
                    retval = cmdq_fire_command(item);
                    if retval as i32 == CMD_RETURN_ERROR as i32 {
                        cmdq_remove_group(item);
                    }
                }
                1 => {
                    retval = cmdq_fire_callback(item);
                }
                _ => {
                    retval = CMD_RETURN_ERROR;
                }
            }
            (unsafe { (*item).flags |= 0x1 as i32 });
            if retval as i32 == CMD_RETURN_WAIT as i32 {
                (unsafe { (*item).flags |= 0x2 as i32 });
                current_block = 781873232861654146;
                break;
            } else {
                items = items.wrapping_add(1);
            }
        }
        cmdq_remove(item);
    }
    match current_block {
        781873232861654146 => {
            (unsafe {
                log_debug(
                    b"%s %s: exit (wait)\0" as *const u8 as *const i8,
                    (*::core::mem::transmute::<&[u8; 10], &[i8; 10]>(b"cmdq_next\0")).as_ptr(),
                    name,
                )
            });
            return items;
        }
        _ => {
            (unsafe { (*queue).item = std::ptr::null_mut::<cmdq_item>() });
            (unsafe {
                log_debug(
                    b"%s %s: exit (empty)\0" as *const u8 as *const i8,
                    (*::core::mem::transmute::<&[u8; 10], &[i8; 10]>(b"cmdq_next\0")).as_ptr(),
                    name,
                )
            });
            return items;
        }
    };
}
#[no_mangle]
pub extern "C" fn cmdq_running(mut c: *mut client) -> *mut cmdq_item {
    let mut queue: *mut cmdq_list = cmdq_get(c);
    if (unsafe { (*queue).item }).is_null() {
        return std::ptr::null_mut::<cmdq_item>();
    }
    if (unsafe { (*(*queue).item).flags }) & 0x2 as i32 != 0 {
        return std::ptr::null_mut::<cmdq_item>();
    }
    return unsafe { (*queue).item };
}
#[no_mangle]
pub extern "C" fn cmdq_guard(mut item: *mut cmdq_item, mut guard: *const i8, mut flags: i32) {
    let mut c: *mut client = unsafe { (*item).client };
    let mut t: i64 = unsafe { (*item).time };
    let mut number: u_int = unsafe { (*item).number };
    if !c.is_null() && (unsafe { (*c).flags }) & 0x2000 as i32 as u64 != 0 {
        (unsafe {
            control_write(
                c,
                b"%%%s %ld %u %d\0" as *const u8 as *const i8,
                guard,
                t,
                number,
                flags,
            )
        });
    }
}
#[no_mangle]
pub extern "C" fn cmdq_print_data(
    mut item: *mut cmdq_item,
    mut parse: i32,
    mut evb: *mut evbuffer,
) {
    (unsafe { server_client_print((*item).client, parse, evb) });
}
#[no_mangle]
pub unsafe extern "C" fn cmdq_print(mut item: *mut cmdq_item, mut fmt: *const i8, mut args: ...) {
    let mut ap: ::core::ffi::VaListImpl;
    let mut evb: *mut evbuffer = std::ptr::null_mut::<evbuffer>();
    evb = evbuffer_new();
    if evb.is_null() {
        fatalx(b"out of memory\0" as *const u8 as *const i8);
    }
    ap = args.clone();
    evbuffer_add_vprintf(evb, fmt, ap.as_va_list());
    cmdq_print_data(item, 0 as i32, evb);
    evbuffer_free(evb);
}
#[no_mangle]
pub unsafe extern "C" fn cmdq_error(mut item: *mut cmdq_item, mut fmt: *const i8, mut args: ...) {
    let mut c: *mut client = (*item).client;
    let mut cmd: *mut cmd = (*item).cmd;
    let mut ap: ::core::ffi::VaListImpl;
    let mut msg: *mut i8 = std::ptr::null_mut::<i8>();
    let mut tmp: *mut i8 = std::ptr::null_mut::<i8>();
    let mut file: *const i8 = std::ptr::null::<i8>();
    let mut line: u_int = 0;
    ap = args.clone();
    xvasprintf(&mut msg, fmt, ap.as_va_list());
    log_debug(
        b"%s: %s\0" as *const u8 as *const i8,
        (*::core::mem::transmute::<&[u8; 11], &[i8; 11]>(b"cmdq_error\0")).as_ptr(),
        msg,
    );
    if c.is_null() {
        cmd_get_source(cmd, &mut file, &mut line);
        cfg_add_cause(b"%s:%u: %s\0" as *const u8 as *const i8, file, line, msg);
    } else if ((*c).session).is_null() || (*c).flags & 0x2000 as i32 as u64 != 0 {
        server_add_message(
            b"%s message: %s\0" as *const u8 as *const i8,
            (*c).name,
            msg,
        );
        if !(*c).flags & 0x10000 as i32 as u64 != 0 {
            tmp = msg;
            msg = utf8_sanitize(tmp);
            free(tmp as *mut libc::c_void);
        }
        if (*c).flags & 0x2000 as i32 as u64 != 0 {
            control_write(c, b"%s\0" as *const u8 as *const i8, msg);
        } else {
            file_error(c, b"%s\n\0" as *const u8 as *const i8, msg);
        }
        (*c).retval = 1 as i32;
    } else {
        *msg = toupper(*msg as u_char as i32) as i8;
        status_message_set(
            c,
            -(1 as i32),
            1 as i32,
            0 as i32,
            b"%s\0" as *const u8 as *const i8,
            msg,
        );
    }
    free(msg as *mut libc::c_void);
}
